package com.wfl.sampling.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


@Component
@Aspect
@Slf4j
public class TimeAspect {
    @Pointcut("execution(* com.wfl.sampling.service.impl.LoadFileServiceImpl.*(..))")
    void pt(){//抽取相同的切入点，简化修改
    }
    @Around("pt()")//切入点表达式
    public Object recordAspect(ProceedingJoinPoint pjp ) throws Throwable {
        long begin = System.currentTimeMillis();
        Object result = pjp.proceed();
        long end  =System.currentTimeMillis();
        log.info(pjp.getSignature()+"执行时间：{}ms",end-begin);
        return  result;
    }

    @Around("@annotation(com.wfl.sampling.aop.RunTimeGet)")//切入点表达式
    public Object recordTimeAspect(ProceedingJoinPoint pjp ) throws Throwable {
        long begin = System.currentTimeMillis();
        Object result = pjp.proceed();
        long end  =System.currentTimeMillis();
        log.info(pjp.getSignature()+"执行时间：{}ms",end-begin);
        return  result;
    }
}
